package com.itheima.mall.controller.omsController;

import com.itheima.PageResult;
import com.itheima.mall.service.omsService.OmsOrderReturnReasonApi;
import com.itheima.mall.service.omsService.OmsOrderReturnReasonService;
import com.itheima.pojo.oms.OmsOrderReturnReason;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/returnReason")
public class OmsOrderReturnReasonController {
    @Autowired
    private OmsOrderReturnReasonService omsOrderReturnReasonService;

    /**
     * 分页查询退回原因
     * @param pageNum
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public ResponseEntity<PageResult<OmsOrderReturnReason>> findByPage(@RequestParam(value = "pageNum",defaultValue = "1",required = false)Integer pageNum,
                                                                       @RequestParam(value = "pageSize",defaultValue = "10",required = false)Integer pageSize){
       PageResult<OmsOrderReturnReason>  pageResult = omsOrderReturnReasonService.findByPage(pageNum,pageSize);
         return ResponseEntity.ok(pageResult);
    }


    /**
     * 批量删除退货原因
     * @param ids
     * @return
     */
    @PostMapping("/delete")
    public ResponseEntity deleteReturnReason(Integer[] ids){
        omsOrderReturnReasonService.deleteReturnReason(ids);
        return ResponseEntity.ok(null);
    }



    /**
     * 修改退货原因启用状态
     * @param ids
     * @param status
     * @return
     */
    @PostMapping("/update/status")
    public ResponseEntity updateStatus(Integer[] ids, Integer status){
        omsOrderReturnReasonService.updateStatus(ids,status);
        return ResponseEntity.ok(null);
    }
    /**
     * 获取单个退货原因详情信息
     * @param id
     * @return
     */
    @GetMapping("/{id}")
    public ResponseEntity getInfoById(@PathVariable Integer id){
        OmsOrderReturnReason returnReason = omsOrderReturnReasonService.getById(id);
        return ResponseEntity.ok(null);
    }

    /**
     * 修改退货原因
     * @param id
     * @param orderReturnReason
     * @return
     */
    @PostMapping("/update/{id}")
    public ResponseEntity updateById(@PathVariable Integer id,@RequestBody OmsOrderReturnReason orderReturnReason){
        omsOrderReturnReasonService.updateById(id,orderReturnReason);
        return ResponseEntity.ok(null);
    }


    /**
     * 添加退货原因
     * @param omsOrderReturnReason
     * @return
     */
    @PostMapping("/create")
    public ResponseEntity save(@RequestBody OmsOrderReturnReason omsOrderReturnReason){
         omsOrderReturnReasonService.save(omsOrderReturnReason);
        return ResponseEntity.ok(null);
    }
}
